package com.ferrlo.web.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ferrlo.model.Project;
import com.ferrlo.service.IProjectManager;

@Controller
public class PrjectDetailsController {
	
	@Resource(name="projectManager")
	private IProjectManager projectmanager;
	
	@RequestMapping(value="/projDetails")
	public String toDetails(Map<String, Object> map, HttpServletRequest request){
		
		String pid = request.getParameter("pid");
		System.out.println(pid);
		Project project = findProjectByPid(pid);
		request.setAttribute("project", project);

		return "project";
	}
	
	private Project findProjectByPid(String pid){
		
		String dqQuery = "ProjectManager.findProjectByPid.query";
		Map<String, Object> paras = new HashMap<String, Object>();
		paras.put("id", pid);
		List<Project> projects = projectmanager.findListByDynamicQuery(dqQuery, paras);
		if (projects != null && projects.size() != 0) {
			return projects.get(0);
		}
		
		return null;
	}
	

}
